package com.spyrx7.fang_erhuo.util;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;

import java.util.Map;

/**
 * Created by pc-spyrx7 on 2015/12/31.
 * 作者  pc-spyrx7
 * 邮箱 spyhanfeng@qq.com
 */
public class HttpUtil {
    public static final String TAG = "HttpUtil";
    //http://qt.quseit.cn:12000/api/get
    public static  final String API = "http://qt.quseit.cn:12000/api/";

    public static void post(Context context,String url, final Map<String,String> parms,Response.Listener<String> listener, Response.ErrorListener errorListener){
        VolleyUtil.getRequestQueue(context.getApplicationContext()).cancelAll(context.getApplicationContext());
        String base_url = API + url;
        StringRequest sr = new StringRequest(Request.Method.POST, base_url,listener,errorListener){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return parms;
            }
        };
        VolleyUtil.getRequestQueue(context.getApplicationContext()).add(sr);
    }

    public static void get(Context context,String url, Response.Listener<String> listener, Response.ErrorListener errorListener){
        VolleyUtil.getRequestQueue(context.getApplicationContext()).cancelAll(context.getApplicationContext());
        StringRequest sr = new StringRequest(Request.Method.GET,url,listener,errorListener){
        /*    @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Charset", "gb2312");
                headers.put("Content-Type", "application/x-javascript");
                headers.put("Accept-Encoding", "gzip,deflate");
                return headers;
            }*/
        };
        VolleyUtil.getRequestQueue(context.getApplicationContext()).add(sr);
    }
}
